package com.fr.data.impl;

import com.fr.base.core.ComparatorUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.data.Dictionary.MV;
import com.fr.data.TableData;
import com.fr.data.core.DataXMLUtils;
import com.fr.report.script.Calculator;
import java.util.Iterator;
import java.util.List;

public class TableDataDictionary extends FormulaDisplayDictionary
{
  private TableData tableData;
  private transient List kvs;

  public TableDataDictionary()
  {
    this(TableData.EMPTY_TABLEDATA, 0, 1);
  }

  public TableDataDictionary(TableData paramTableData, int paramInt1, int paramInt2)
  {
    setTableData(paramTableData);
    setKeyColumnIndex(paramInt1);
    setValueColumnIndex(paramInt2);
  }

  public void setTableData(TableData paramTableData)
  {
    this.tableData = paramTableData;
  }

  public TableData getTableData()
  {
    return this.tableData;
  }

  public void reset()
  {
    this.kvs = null;
  }

  private void createKVS(Calculator paramCalculator)
  {
    if (this.kvs == null)
      this.kvs = createMVList(getTableData(), paramCalculator);
  }

  public Object get(Object paramObject, Calculator paramCalculator)
  {
    createKVS(paramCalculator);
    int i = 0;
    int j = this.kvs.size();
    while (i < j)
    {
      Dictionary.MV localMV = (Dictionary.MV)this.kvs.get(i);
      if (ComparatorUtils.equals(localMV.getModel(), paramObject))
        return localMV.getView();
      ++i;
    }
    return null;
  }

  public String[] getDependence()
  {
    return super.getDependence();
  }

  public Iterator entrys(Calculator paramCalculator)
  {
    createKVS(paramCalculator);
    return new EntryIterator(this, null);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (("TableDataDictAttr".equals(str1)) || ("TableDataMapAttr".equals(str1)))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("keyColumnIndex")) != null)
          setKeyColumnIndex(Integer.parseInt(str2) - 1);
        if ((str2 = paramXMLableReader.getAttr("valueColumnIndex")) != null)
          setValueColumnIndex(Integer.parseInt(str2) - 1);
        if ((str2 = paramXMLableReader.getAttr("tableDataName")) != null)
          setTableData(new NameTableData(str2));
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final TableDataDictionary this$0;

          public void readXML()
          {
            if (paramXMLableReader.isChildNode())
            {
              if ("TableData".equals(paramXMLableReader.getTagName()))
                this.this$0.setTableData(DataXMLUtils.readXMLTableData(paramXMLableReader));
              if ("Condition".equals(paramXMLableReader.getTagName()))
                this.this$0.condition = DataXMLUtils.readCondition(paramXMLableReader);
            }
          }
        });
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("TableDataDictAttr");
    DataXMLUtils.writeXMLTableData(paramXMLPrintWriter, getTableData());
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (paramObject == this)
      return true;
    if (!(paramObject instanceof TableDataDictionary))
      return false;
    return super.equals(paramObject);
  }

  public String toString()
  {
    return "TableDataDict[" + getTableData() + "]";
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    TableDataDictionary localTableDataDictionary = (TableDataDictionary)super.clone();
    return localTableDataDictionary;
  }

  static List access$100(TableDataDictionary paramTableDataDictionary)
  {
    return paramTableDataDictionary.kvs;
  }

  private class EntryIterator
    implements Iterator
  {
    private int next;
    private final TableDataDictionary this$0;

    private EntryIterator()
    {
      this.this$0 = paramTableDataDictionary;
      this.next = 0;
    }

    public boolean hasNext()
    {
      return (this.next < TableDataDictionary.access$100(this.this$0).size());
    }

    public Object next()
    {
      Object localObject = TableDataDictionary.access$100(this.this$0).get(this.next);
      this.next += 1;
      return localObject;
    }

    public void remove()
    {
    }

    EntryIterator(, TableDataDictionary.1 param1)
    {
      this(paramTableDataDictionary);
    }
  }
}